<template>
  <div class="battery-view">
    <span class="text-[14px] font-bold text-[#262626]">{{ batteryLevel }}%</span>

    <div class="battery-container">
      <div
        class="battery-level"
        :style="{
          width: `${batteryLevel}%`,
          backgroundColor: batteryColor,
        }"
      ></div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed } from "vue";

const props = defineProps<{
  batteryLevel: number;
}>();

// 根据电量计算显示颜色
const batteryColor = computed(() => {
  if (props.batteryLevel <= 20) return "#ff4d4f"; // 红色
  return "#40D8B9"; // 绿色
});
</script>

<style scoped>
.battery-view {
  display: flex;
  flex-direction: column;
  align-items: start;
  gap: 4px;
}

.battery-container {
  width: 24px;
  height: 12px;
  border: 1px solid #9ca0a6;
  border-radius: 3px;
  padding: 2px 2px 2px 2px;
  position: relative;
}

.battery-container::after {
  content: "";
  position: absolute;
  width: 2px;
  height: 5px;
  background: #9ca0a6;
  right: -5px;
  top: 50%;
  transform: translateY(-50%);
  border-radius: 0 2px 2px 0;
}

.battery-level {
  height: 100%;
  border-radius: 1px;
  transition: all 0.3s ease;
}
</style>
